package com.byx.chatclient.adapter;

import android.text.TextUtils;

import com.byx.chatclient.R;
import com.byx.chatclient.bean.SearchGroupBean;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.facebook.drawee.view.SimpleDraweeView;

import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

import java.util.List;

/**
 * SearchGroupAdapter
 * 搜索群聊列表适配器
 * @author Superb
 * @date 2021/4/26 21:14
 */
public class SearchGroupAdapter extends BaseQuickAdapter<SearchGroupBean, BaseViewHolder> {
    private static final int LAYOUT_RES_ID = R.layout.layout_search_group_item;

    public SearchGroupAdapter(@Nullable List<SearchGroupBean> data) {
        super(LAYOUT_RES_ID, data);
        init();
    }

    public SearchGroupAdapter() {
        super(LAYOUT_RES_ID);
        init();
    }

    private void init() {
        addChildClickViewIds(R.id.btn_add_group);
    }

    @Override
    protected void convert(@NotNull BaseViewHolder baseViewHolder, SearchGroupBean searchGroupBean) {
        ((SimpleDraweeView) baseViewHolder.getView(R.id.sdv_group_avatar)).setImageURI(searchGroupBean.getGroupAvatar());
        baseViewHolder.setText(R.id.tv_group_name_and_account,String.format("%s(%s)",searchGroupBean.getGroupName(),searchGroupBean.getGroupId()));
        baseViewHolder.setText(R.id.tv_user_count,String.format("人数：%s",searchGroupBean.getUserCount()));
        baseViewHolder.setText(R.id.tv_group_description, TextUtils.isEmpty(searchGroupBean.getDescription()) ? "群主很懒，暂未编辑群介绍" : searchGroupBean.getDescription());
    }
}
